package com.github.bryx.workflowweb.controller.query;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.bryx.workflow.domain.WorkflowDef;
import com.github.bryx.workflow.domain.WorkflowDefRev;
import com.github.bryx.workflow.dto.buildtime.QueryWorkflowDefDto;
import com.github.bryx.workflow.dto.buildtime.QueryWorkflowDefRevDto;
import com.github.bryx.workflow.service.WorkflowBuildTimeQuery;
import com.github.bryx.workflowweb.config.entity.ResultEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author lancer.zyj
 * @date 2021/7/7 7:15 下午
 */
@RestController
@RequestMapping("/build/query")
@Api(tags = "工作流查询")
public class WorkflowBuildTimeQueryController {

    @Autowired
    private WorkflowBuildTimeQuery workflowBuildTimeQuery;

    @PostMapping("/def/")
    @ApiOperation(value = "查询流程定义列表")
    public ResultEntity<Page<WorkflowDef>> queryWorkflowDefs(@RequestBody @Valid QueryWorkflowDefDto<WorkflowDef> param){
        return ResultEntity.of(workflowBuildTimeQuery.queryWorkflowDefs(param));
    }

    @PostMapping("/rev/")
    @ApiOperation(value = "查询流程定义下的版本列表")
    public ResultEntity<Page<WorkflowDefRev>> queryWorkflowDefRevs(@RequestBody @Valid QueryWorkflowDefRevDto<WorkflowDefRev> param){
        return ResultEntity.of(workflowBuildTimeQuery.queryWorkflowDefRevs(param));
    }

}
